<?php
use yii\helpers\Url;
?>
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>铝邦CRM客户管理系统</title>
    <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css"/>
    <link rel="stylesheet" href="css/common.css"/>
    <link rel="stylesheet" href="css/public.css"/>
    <link rel="stylesheet" href="css/setting.css"/>
    <script src="js/jquery-1.12.3.min.js"></script>
    <script src="layui/layui.all.js"></script>
</head>
<body class="body-set">
<div class="main-nav">
    <h3>参数设置</h3>
</div>
<div class="log-wap">
    <span class="clues para-on">线索</span>
    <span class="client">企业</span>
    <span class="follow">跟进</span>
</div>
<div class="clues-wap">
    <div class="para-nav">
        <span>线索来源</span>
    </div>
    <div class="para-list">
        <table>
            <tr>
                <td class="col-sm-2">排序</td>
                <td class="col-sm-3">类型</td>
            </tr>
            <?php foreach($clueOrginList as $key=>$value){

            ?>
                <tr>
                    <td class="col-sm-2"><?=$key+1?></td>
                    <td class="col-sm-3"><span><?=$value['name']?></span><button onclick='deleteParams(this,<?=$value['id']?>,1)'>删除</button></td></td>
                </tr>
            <?php
            }
            ?>

        </table>
    </div>
    <div class="add-clues-list"  type="1">
        <span>添加</span>
    </div>
</div>
<div class="clues-wap">
    <div class="follow-nav">
        <span>跟进状态</span>
    </div>
    <div class="para-list">
        <table>
            <tr>
                <td class="col-sm-2">排序</td>
                <td class="col-sm-3">类型</td>
            </tr>
            <?php foreach($clueFollowTypeList as $key=> $value){

                ?>
                <tr>
                    <td class="col-sm-2"><?=$key+1?></td>
                    <td class="col-sm-3"><span><?=$value['name']?></span><button onclick='deleteParams(this,<?=$value['id']?>,2)'>删除</button></td></td>
                </tr>
                <?php
            }
            ?>
        </table>
    </div>
    <div class="add-clues-list"  type="2">
        <span>添加</span>
    </div>

</div>
<div class="client-wap">
    <div class="follow-nav">
        <span>公司类型</span>
    </div>
    <div class="para-list">
        <table>
            <tr>
                <td class="col-sm-2">排序</td>
                <td class="col-sm-3">类型</td>
            </tr>
            <?php foreach($companyCatsList as $key=> $value){

                ?>
                <tr>
                    <td class="col-sm-2"><?=$key+1?></td>
                    <td class="col-sm-3"><span><?=$value['typeName']?></span><button onclick='deleteParams(this,<?=$value['id']?>,3)'>删除</button></td></td>
                </tr>
                <?php
            }
            ?>
        </table>
    </div>
    <div class="add-clues-list"  type="3">
        <span>添加</span>
    </div>

</div>
<div class="client-wap">
    <div class="follow-nav">
        <span>企业等级</span>
    </div>
    <div class="para-list">
        <table>
            <tr>
                <td class="col-sm-2">排序</td>
                <td class="col-sm-3">类型</td>
            </tr>
            <?php foreach($gradeList as $key=>$value){

                ?>
                <tr>
                    <td class="col-sm-2"><?=$key+1?></td>
                    <td class="col-sm-3"><span><?=$value['name']?></span><button onclick='deleteParams(this,<?=$value['id']?>,4)'>删除</button></td></td>
                </tr>
                <?php
            }
            ?>
        </table>
    </div>
    <div class="add-clues-list"  type="4">
        <span>添加</span>
    </div>

</div>
<div class="client-wap">
    <div class="follow-nav">
        <span>跟进状态</span>
    </div>
    <div class="para-list">
        <table>
            <tr>
                <td class="col-sm-2">排序</td>
                <td class="col-sm-3">类型</td>
            </tr>
            <?php foreach($enterFollowTypeList as $key=>$value){

                ?>
                <tr>
                    <td class="col-sm-2"><?=$key+1?></td>
                    <td class="col-sm-3"><span><?=$value['name']?></span><button onclick='deleteParams(this,<?=$value['id']?>,5)'>删除</button></td></td>
                </tr>
                <?php
            }
            ?>
        </table>
    </div>
    <div class="add-clues-list"  type="5">
        <span>添加</span>
    </div>

</div>
<div class="follow-wap">
    <div class="follow-nav">
        <span>跟进方式</span>
    </div>
    <div class="para-list">
        <table>
            <tr>
                <td class="col-sm-2">排序</td>
                <td class="col-sm-3">类型</td>
            </tr>
            <?php foreach($followTypeList as $key=>$value){

                ?>
                <tr>
                    <td class="col-sm-2"><?=$key+1?></td>
                    <td class="col-sm-3"><span><?=$value['name']?></span><button onclick='deleteParams(this,<?=$value['id']?>,6)'>删除</button></td></td>
                </tr>
                <?php
            }
            ?>
        </table>
    </div>
    <div class="add-clues-list"  type="6">
        <span>添加</span>
    </div>

</div>
<div class="follow-wap">
    <div class="follow-nav">
        <span>配合程度</span>
    </div>
    <div class="para-list">
        <table>
            <tr>
                <td class="col-sm-2">排序</td>
                <td class="col-sm-3">类型</td>
            </tr>
            <?php foreach($coordinationList as $key=>$value){

                ?>
                <tr>
                    <td class="col-sm-2"><?=$value['sort']?></td>
                    <td class="col-sm-3"><span><?=$value['name']?></span><button onclick='deleteParams(this,<?=$value['id']?>,7)'>删除</button></td>
                </tr>
                <?php
            }
            ?>
        </table>
    </div>
    <div class="add-clues-list" type="7">
        <span>添加</span>
    </div>

</div>
<script>
    $(function () {
        function addCluesList(){
            var $exm = $(".para-list tr").length-1;
            var $tr = "<tr><td class='col-sm-2'>"+$exm+"</td><td class='col-sm-3'><span></span><input type='text' name='inputChar'><button class='save'>保存</button><button class='dels'>删除</button></td></tr>";
            $(".para-list table").append($tr);
        }
        $(function () {
            $("tr .col-sm-3").find("button").hide();
        })
        $("tr .col-sm-3").hover(function () {
            $(this).find("button").show();
        }, function () {
            $(this).find("button").hide();
        });
        $(".log-wap span").click(function () {
            $(this).siblings().removeClass("para-on");
            $(this).addClass("para-on");
            var index = $(this).index();
            if(index == 0){
                $(".clues-wap").show();
                $(".client-wap").hide();
                $(".follow-wap").hide();
            }else if(index == 1){
                $(".clues-wap").hide();
                $(".client-wap").show();
                $(".follow-wap").hide();
            }else{
                $(".clues-wap").hide();
                $(".client-wap").hide();
                $(".follow-wap").show();
            }
        });
        $(".add-clues-list").on("click", function () {
            console.log($(this).attr('type'));
            var it = $(this);
            var $exm =$(it).siblings(".para-list").find("tr").length-1;
            var $tr = "<tr><td class='col-sm-2'>"+$exm+"</td><td class='col-sm-3'><span></span><input type='text' name='inputChar'><button class='save' theType='"+$(this).attr('type')+"'>保存</button><button class='dels'>删除</button></td></tr>";
            $(it).siblings(".para-list").find("table").append($tr);

            $(".para-list").on("click",".save", function () {
                var date ={};
                var input = $(this).parents("tr").find("input");
                var span =  $(this).parents("tr").find("span");
                var button = $(this).parents("tr").find("button");
                var id=$(this).parents("tr").find(".col-sm-2").text();
//                date.id = parseInt(id);
                 date.name = $(this).parents("tr").find("input").val();
                date.type=$(this).attr('theType');
                var url='<?=Url::toRoute(['params/add-params'])?>';
                $.post(url,date, function (data) {
                        var data=JSON.parse(data);
                        if(data.errcode==0){
                            $(input).css("display","none");
                            $(button).css("display","none");
                            $(span).text(date.name);
                            layer.msg(data.errmsg);
                        }else{
                            layer.msg(data.errmsg);
                        }

                })
            });
        });
        $(".para-list").on("click",".dels", function () {
            var url ='';
            var des = $(this).parents("tr");
            var date = $(this).parents("tr").find(".col-sm-2").text();
            date = parseInt(date);
            $.post(url,date, function () {
                error:{
                    $(des).remove();
                    layer.msg("删除成功");
                }
            })
            $(this).parents("tr").remove();
        });
        $(".para-list").on("mouseover",".col-sm-3", function () {
            $(this).find(".dels").show();
        });
        $(".para-list").on("mouseout",".col-sm-3", function () {
            $(this).find(".dels").hide();
        })
    })
    /**
     * 删除参数
     */
    function deleteParams(object,id,type){
        var params={};
        params.id=id;
        params.type=type;
        var url="<?=Url::toRoute(['params/delete-params'])?>";
        var des = $(object).parents("tr");
        $.post(url,params,function(data){
            var data=JSON.parse(data);{
                if(data.errcode==0){
                    des.remove();
                    layer.msg(data.errmsg);
                }else{
                    layer.msg(data.errmsg);
                }
            }
        });
    }
</script>
</body>
</html>